package com.tzinfo.tzt.fragment;


import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.tzinfo.tzt.R;
import com.tzinfo.tzt.util.Picdata;

import java.util.List;

/**
 * Created by Administrator on 2014/11/11.
 */
public class Cars4smodeFragmetImage0 extends Fragment {
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "url";
    // TODO: Rename and change types of parameters
    private int mParam1;
    private String mUrl;

    private ImageView image;
    private ImageLoader imageLoader;

    private Context context;
    private int photoImageId[] = {R.drawable.a31,R.drawable.aodi,R.drawable.benchi,R.drawable.q31};

    public static Cars4smodeFragmetImage0 newInstance(int position, List<Picdata> url_data) {
        Cars4smodeFragmetImage0 fragment = new Cars4smodeFragmetImage0();

        Bundle args = new Bundle();
        args.putInt(ARG_PARAM1, position);
        args.putString(ARG_PARAM2, url_data.get(position).getP());
        fragment.setArguments(args);
        return fragment;
    }
    public Cars4smodeFragmetImage0() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getInt(ARG_PARAM1);
            if(getArguments().getString(ARG_PARAM2) !=null)
            mUrl =getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        context = activity;
        imageLoader = ImageLoader.getInstance();    }

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.cars4mode_fragment, container, false);
        image =(ImageView)v.findViewById(R.id.image);
        return v;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if(mUrl !=null)
        imageLoader.displayImage(mUrl, image);
//        InputStream is = this.getResources().openRawResource(photoImageId[mParam1]);
//        BitmapFactory.Options options=new BitmapFactory.Options();
//        options.inJustDecodeBounds = false;
//        //  options.inSampleSize = 10;   //width，hight设为原来的十分一
//        Bitmap btp = BitmapFactory.decodeStream(is, null, options);
//        image.setImageBitmap(btp);
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }
}
